<template>
  <div id="home">
    <div class="">
      <el-button type="primary" @click="refresh()">刷新</el-button>
      <div class="head row">
        <div>
          <leftTypeList
            :navList="navList"
            label="typeName"
            path="/filter"
          ></leftTypeList>
          <img width="180" src="@/assets/imgs/left.png" alt="" />
        </div>

        <div class="swiper">
          <myswiper></myswiper>
          <bookList1
            lwidth="800"
            colNum="5"
            :bookList="bookList"
            v-if="bookList"
          ></bookList1>
        </div>
      </div>
      <div>
        <div class="bookList2">
          <bookList2
            :key="1"
            :bookList="bookList"
            v-if="bookList"
            lable="好书推荐"
          ></bookList2>
        </div>
      </div>
      <div>
        <div class="bookList2">
          <bookList2
            :key="2"
            :bookList="bookList"
            v-if="bookList"
            lable="新书推荐"
          ></bookList2>
        </div>
      </div>
      <div>
        <div class="bookList2">
          <bookList2
            :key="3"
            :bookList="bookList"
            v-if="bookList"
            lable="最近畅销"
          ></bookList2>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { onlyNumOnePoint } from "@/assets/myjs/function.js";
export default {
  data() {
    return {
      bookList: [],
      findByPage: {
        userId: 0,
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  computed: {
    navList: function () {
      return this.$store.state.bookType.bookTypeList.allBookTypeList;
    },
  },
  created() {
    this.findAll();
  },
  components: {
    myswiper: () => import("@/components/util/swiper.vue"),
    bookList1: () => import("@/components/book/bookList1.vue"),
    bookList2: () => import("@/components/book/bookList2.vue"),
    leftTypeList: () => import("@/components/base/leftTypeList.vue"),
  },
  methods: {
    findAll() {
      this.$axios
        .post("index/sys/book/getBooksByPage", this.findByPage)
        .then(({ data }) => {
          // console.log("home", data);
          this.bookList = data.bookInfo;
        });
    },
    refresh() {
      this.$axios
        .post("index/sys/book/refreshTES", this.findByPage)
        .then(({ data }) => {
          if (data.code == 201) {
            findAll();
            this.$message.success("刷新成功");
          } else {
            this.$message.error("刷新失败");
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
@font-face {
  font-family: "font2";
  src: url("@/assets/font/e.ttf");
}

.swiper {
  // padding-left: 180px;
  width: 100%;
  padding: 20px;
  background: rgb(220, 216, 216);
}

.bookList2 {
  margin-top: 30px;
}
.bookList2:nth-child(1 + n) {
  background: rgb(228, 58, 58);
}
</style>